package cn.csxw.openchina.dagger2.presenter;

import java.util.ArrayList;

import javax.inject.Inject;

import cn.csxw.openchina.entity.bean.BlogBean;
import cn.csxw.openchina.entity.bean.OsChinaBean;
import cn.csxw.openchina.ui.fragment.myFragment.MyBlogFragment;
import retrofit2.Call;

/**
 * Created by hp on 2017/1/18.
 */

public class MyBlogFragmentPresenter extends BasePresenter {
    MyBlogFragment mMyBlogFragment;

    @Inject
    public MyBlogFragmentPresenter(MyBlogFragment myBlogFragment) {
        mMyBlogFragment = myBlogFragment;
    }

    @Override
    protected void processData(OsChinaBean data) {
        if(data!=null){
            ArrayList<BlogBean> blogs = (ArrayList<BlogBean>) data.blogs;
            if(  mMyBlogFragment.mMyBlogAdapter.getData().size()>0){
                mMyBlogFragment.mMyBlogAdapter.addData(blogs);
            }else {
                mMyBlogFragment.mMyBlogAdapter.setData(blogs);
            }
            mMyBlogFragment.loadMoreCompleted();
            mMyBlogFragment.mSrfLayout.setRefreshing(false);
        }
    }

    @Override
    public void callNetWork(Object... params) {
        Call<OsChinaBean> myblogInfo = mOsChinaServer.getUserBlogInfo((String)params[0],(String)params[1],(int)params[2],(String)params[3],(int)params[4]);
        myblogInfo.enqueue(mCallback);
    }
}
